import { _decorator, Component, Node } from 'cc';
import { Core } from './Core/Core';
import { EEvent, EGameMode, EPet, EPlayerType } from './Config/Enum';
const { ccclass, property } = _decorator;

@ccclass('PetListItem')
export class PetListItem extends Component {
    //: Node = null;  
    msg


    protected onLoad(): void {
        this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
        //this.ndReddot = this.node.getChildByName("reddot");
        
    }

    protected onEnable(): void {
        this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
    }

    protected onDisable(): void {
        // 清理事件监听
        this.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this);
        
    }


    start() {
        //


    }

    update(deltaTime: number) {
        
    }


    // showReddot(){
    //     this.ndReddot.active = true;
    // }


    onTouchStart(){
        // 处理触摸开始事件

        // 判断有没有解锁，如果有解锁
        //console.log("宠物列表点击Core.Instance.unlockedPets",Core.Instance.unlockedPets);  
        if (Core.Instance.unlockedPets.indexOf(this.node.name as EPet)!== -1) {
            Core.Instance.currentPet = this.node.name as EPet;
            Core.Instance.event.emit(EEvent.PetUpdate);
        } else {
            //console.log("当前玩家未解锁", this.node.name);


            this.msg = "当前灵兽未解锁";
            // let currentStage = Core.Instance.modeMaxStage[EGameMode.Normal];
            // if(currentStage < 3){
            //     this.msg = "通过襄阳烽烟第 3 关招募下一位义士";   
            // }
            // if(currentStage >= 3 && currentStage < 7){
            //     this.msg = "通过襄阳烽烟第 7 关招募下一位义士";   
            // }
            // if(currentStage >= 7 && currentStage < 13){
            //     this.msg = "通过襄阳烽烟第 13 关招募下一位义士";   
            // }
            // if(currentStage >= 13 && currentStage < 19){
            //     this.msg = "通过襄阳烽烟第 19 关招募下一位义士";   
            // }
            // if(currentStage >= 19 && currentStage < 25){
            //     this.msg = "通过襄阳烽烟第 25 关招募下一位义士";   
            // }



            // 显示Tips
            Core.Instance.showTips(this.msg);
            





            //Core.Instance.event.emit(EEvent.PlayerNotUnlocked, this.node.name);
        }
    }
}


